/**
 * Copyright (c) Css Team
 * All rights reserved.
 *
 * This file AddSysAction.java creation date: [2014-1-8 09:30:20] by Xingzhc
 * http://www.css.com.cn
 */
package com.css.apps.base.recycle.action;

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.base.dict.service.DictMan;
import com.css.apps.base.recycle.model.RTrash;
import com.css.db.page.Page;
import com.css.db.query.QueryCache;
import com.css.util.DateUtil;
import com.css.util.LogUtil;
import com.css.util.Messages;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

/**
 * <p>查询回收站分页列表</p>
 * @author CSS
 *
 */
@SuppressWarnings("serial")
public class DirRecycle extends AdminAction {
	private static final Log log = LogFactory.getLog(DirRecycle.class);
	private final String funcid = "ACL_DIRRECYCLE";
	//原位置
	private String funcName;
	//操作人
	private String operatorName;

	// 回收起止时间
	private Date beginCollectTime;
	private Date endCollectTime;
	//内存分页
	private Page page;
	
	public DirRecycle() { 
		page = new Page();
		page.setCountField("a.entityId");
		setFuncid(funcid);
	}
	
	protected String adminGo() {
		try {
			QueryCache qc = new QueryCache(" select a.entityId from RTrash a  " + getWhere() + getOrder());
			setWhere(qc);
			page = qc.page(page);
			page.setResults(QueryCache.idToObj(RTrash.class, page.getResults()));
			//添加查询操作日志
			LogUtil.dir(RTrash.class);
			return Action.SUCCESS;
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			setMessage(Messages.getString("systemMsg.exception"));
			return Action.ERROR;
		}
	}
	
	public String getOrder() {
		return StringHelper.isNotEmpty(page.getOrderByString()) ? page.getOrderByString() : " order by a.createdTime desc ";
	}
	public String getWhere() {
		StringBuffer sb = new StringBuffer("where (1 = 1)");
		if(StringHelper.isNotEmpty(funcName)) 
			sb.append(" and (a.funcName=:funcName) ");
		if(StringHelper.isNotEmpty(operatorName))
			sb.append(" and (a.opName like :operatorName) ");
		if(beginCollectTime != null)
			sb.append(" and (a.createdTime>=:beginCollectTime) ");
		if(endCollectTime != null)
			sb.append(" and (a.createdTime<:endCollectTime) ");
		return sb.toString();
	}

	public void setWhere(QueryCache qc) {
		if (StringHelper.isNotEmpty(funcName))
			qc.setParameter("funcName", DictMan.getDictType("dataex_d_gwtype", funcName.trim()).getName());
		if (StringHelper.isNotEmpty(operatorName))
			qc.setParameter("operatorName", "%" + operatorName.trim() + "%");
		if(beginCollectTime != null)
			qc.setParameter("beginCollectTime", beginCollectTime);
		if(endCollectTime != null){
			Date tmp = endCollectTime;
			qc.setParameter("endCollectTime", DateUtil.addDate(tmp, 1));
		}
			
	}

	public Date getBeginCollectTime() {
		return beginCollectTime;
	}

	public void setBeginCollectTime(Date beginCollectTime) {
		this.beginCollectTime = beginCollectTime;
	}

	public Date getEndCollectTime() {
		return endCollectTime;
	}

	public void setEndCollectTime(Date endCollectTime) {
		this.endCollectTime = endCollectTime;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}
	
	public String getFuncName() {
		return funcName;
	}

	public void setFuncName(String funcName) {
		this.funcName = funcName;
	}

	public String getOperatorName() {
		return operatorName;
	}

	public void setOperatorName(String operatorName) {
		this.operatorName = operatorName;
	}

}
